package  
{
	import bulletbehavior.AccelerateRelativeBehavior;
	import bulletbehavior.DieBehavior;
	import bulletbehavior.HomeTargetBehavior;
	import bulletbehavior.RotateBehavior;
	import bulletbehavior.SplitBehavior;
	import bulletbehavior.TypeCyclingBehavior;
	import turretbehavior.SpinningTurretBehavior;
	import turretbehavior.TypeCyclingTurretBehavior;
	import org.flixel.FlxG;
	/**
	 * ...
	 * @author morgan
	 */
	public class Stage8State extends GameState
	{
		
		public function Stage8State() 
		{
			levelName = "3-2";
			levelIndex = 7;
			chefName = "julienne";
			img_terrain = img_terrain_3;			
		}
		
		override public function setupBoss():void 
		{
			boss = new Boss(FlxG.width / 2 - 70, 10, 2);
			clouds2.color = 0x000000;
			clouds2.alpha = 0.5;			
			
			var straight:BulletPattern = new BulletPattern();
			
			var slowHoming:BulletPattern = new BulletPattern();
			slowHoming.addBehavior(new HomeTargetBehavior(player, Math.PI / 2), 0.5, 3);
			slowHoming.addBehavior(new AccelerateRelativeBehavior(10, 0));
			
			var quickHoming:BulletPattern = new BulletPattern();
			quickHoming.addBehavior(new HomeTargetBehavior(player, Math.PI * 2), 0.5, 1.0);
			
			var splitIntoHoming:BulletPattern = new BulletPattern();
			splitIntoHoming.addBehavior(new SplitBehavior(10, 90, 180, 0, quickHoming, 2));
			
			var multisplit:BulletPattern = new BulletPattern();
			multisplit.addBehavior(new SplitBehavior(12, 80, -90, 90, straight, 0), 0);
			multisplit.addBehavior(new SplitBehavior(12, 80, -97, 83, straight, 1), 0.2);
			multisplit.addBehavior(new SplitBehavior(12, 80, -90, 90, straight, 2), 0.4);
			multisplit.addBehavior(new SplitBehavior(12, 80, -97, 83, straight, 0), 0.6);
			multisplit.addBehavior(new SplitBehavior(12, 80, -90, 90, straight, 1), 0.8);
			multisplit.addBehavior(new SplitBehavior(12, 80, -97, 83, straight, 2), 1.0);
			multisplit.addBehavior(new DieBehavior(), 1.0);
			
			var multisplit2:BulletPattern = new BulletPattern();
			multisplit2.addBehavior(new SplitBehavior(10, 80, -90, 90, straight, 1), 0);
			multisplit2.addBehavior(new SplitBehavior(10, 80, -99, 81, straight, 2), 0.3);
			multisplit2.addBehavior(new DieBehavior(), 0.3);			
			
			var slowDown:BulletPattern = new BulletPattern();
			slowDown.addBehavior(new AccelerateRelativeBehavior( -20, 0));
			slowDown.addBehavior(new DieBehavior(), 5);
			
			var turn:BulletPattern = new BulletPattern();
			turn.addBehavior(new RotateBehavior( -90, 0), 1.5);
			var turn2:BulletPattern = new BulletPattern();
			turn2.addBehavior(new RotateBehavior(90, 0), 1.5);			
			
			var p1f:BossPattern = new BossPattern();
			var t1t:Turret = new Turret(0, 0, slowHoming, 0, 0, 60, 0.2);
			t1t.addBehavior(new SpinningTurretBehavior(60));
			t1t.addBehavior(new TypeCyclingTurretBehavior(0.4, [0, 1]));
			//var t2t:Turret = new Turret(0, 0, splitIntoHoming, 90, 2, 100, 1);
			var t2t:Turret = new Turret(0, 0, quickHoming, 2, 270, 100, 0.05);
			t2t.addBehavior(new SpinningTurretBehavior(360));			
			p1f.addTurretTime(0, 7, t1t);
			p1f.addTurretTime(8, 9, t2t);
			p1f.setPatternLength(10);
			
			
			
			var p2f:BossPattern = new BossPattern();
			for (var i:int = 0; i < 3; i++)
			{
				var tur:Turret = new Turret(0, 0, turn, i, i * 120, 90, 0.1);
				tur.addBehavior(new SpinningTurretBehavior(45));
				p2f.addTurretTime(0, Infinity, tur);
				
				var tur2:Turret = new Turret(0, 0, turn2, (i + 1) % 3, i * 120 - 60, 90, 0.1);
				tur2.addBehavior(new SpinningTurretBehavior( -90));
				p2f.addTurretTime(10, Infinity, tur2);
			}
			
			
			var p3f:BossPattern = new BossPattern();
			var t3t:Turret = new Turret(0, 0, slowDown, 0, 0, 90, 0.1);
			t3t.addBehavior(new SpinningTurretBehavior(50, 180, true));
			var t4t:Turret = new Turret(0, 0, multisplit2, 0, 90, 10, 0.5);
			p3f.addTurretTime(0, Infinity, t4t);
			p3f.addTurretTime(0, Infinity, t3t);
			
			
			var p4f:BossPattern = new BossPattern();
			var t5t:Turret = new Turret(0, 0, multisplit, 0, 90, 10, 1.1);
			p4f.addTurretTime(0, Infinity, t5t);			
			
			
			boss.addState(new BossState(1600, p1f));
			boss.addState(new BossState(3500, p2f));
			boss.addState(new BossState(1000, p3f));
			boss.addState(new BossState(1000, p4f));			
			
		}
		
	}

}